#!/Applications/xampp/xamppfiles/bin/php

<?php
	$base_path = dirname(dirname(__FILE__) . "../") . '/';
	
	echo "============================================================\n";
	echo "\t\t\tPink Koala Generator\n";
	echo "============================================================\n\n\n";
	
	define("NO_CORE", "don't start up the core");
	require($base_path . "config/config.php");
	require(SYSTEM_DIR . "autoloader.php");
	require(PROJECT_DIR . "scripts" . DS . "generators" . DS . "base_generator.php");
	
	if ($argc < 2 || in_array($argv[1], array('--help', '-help', '-h', '-?')))
	{
		printUsage();
	} 
	else 
	{
		runGenerator($argv);
	}
	
	
	
	
	
	
	
	/**
	 * runGenerator Function
	 *
	 * This function will run the correct generator for the given command
	 *
	 * @param array $params 
	 * @return void
	 * @author Brian Bal
	 */
	
	function runGenerator($params)
	{
		if(count($params) > 0)
		{
			$generator_name = $params[1];
			$generator_class = $generator_name . "Generator";
			$file_name = uncamelize($params[1]);
			$generator_file = PROJECT_DIR . DS . "scripts" . DS . "generators" . DS . $generator_name . DS . $file_name . ".generator.php";
			if(file_exists($generator_file))
			{
				require($generator_file);
				$generator = new $generator_class($params);

			}else{
				echo "\t$generator_file\n";
				printUsage();
			}
		}
		else
		{
			return false;
		}
	}
	
	
	
	/**
	 * printUsage Function
	 *
	 * This function will print the usage info for the generator if the
	 * command that was given is not proper
	 *
	 * @return void
	 * @author Brian Bal
	 */
	
	function printUsage()
	{
		echo "
		  Pink Koala Generator Usage
		==============================
	
		Usage:
	
		<option>
		model <table name> - generates a new mode
		controller <controller name> <actions> - generates a controller
		scaffold <model name> <controller name> - generates CRUD scaffolding
	
		\n\n";
	
		return true;
	}
